/*
pjax_init();
function pjax_init(){
    document.addEventListener('pjax:send', function() {
    	if(navbtn)$("#navbar-toggler-btn").click();
        NProgress.start();
        if(typeof dplayers != "undefined"){
		    for(i in dplayers)
				dplayers[i].destroy();
			dplayers.splice(0,dplayers.length);
		}
		if(typeof hls != "undefined")
			hls.destroy();
		if(typeof dp != "undefined")
			dp.destroy();
	});
    document.addEventListener('pjax:complete', function() {
        NProgress.done();
    });
    document.addEventListener('pjax:error', function() {
    });
    document.addEventListener('pjax:success', function() {
    	//需要重建的js 从next主题复制来的 
	    document.querySelectorAll('script[pjax], #pjax script').forEach(element => {
	    var code = element.text || element.textContent || element.innerHTML || '';
	    var parent = element.parentNode;
	    parent.removeChild(element);
	    var script = document.createElement('script');
	    if (element.id) {
	      script.id = element.id;
	    }
	    if (element.className) {
	      script.className = element.className;
	    }
	    if (element.type) {
	      script.type = element.type;
	    }
	    if (element.src) {
	      script.src = element.src;
	      script.async = false;
	    }
	    if (element.getAttribute('pjax') !== null) {
	      script.setAttribute('pjax', '');
	    }
	    if (code !== '') {
	      script.appendChild(document.createTextNode(code));
	    }
	    parent.appendChild(script);
	});
    });
	document.addEventListener('DOMContentLoaded', function() {
    var pjax = new Pjax({
		elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([target="_blank"])',
		selectors: ["#pjax-container","tocbot","title",".view","#typedjs"]
	});
	pjax._handleResponse = pjax.handleResponse;
	pjax.handleResponse = function(responseText, request, href, options) {
			if(!init1){
					init1=true;
					Promise.all([
						loadExternalResource("https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css", "css"),
						loadExternalResource("/ytyz2020/js/hls.min.js", "js"),
						loadExternalResource("https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js", "js")
					]).then(() => {
						pjax._handleResponse(responseText, request, href, options);
					});
			}else{
			 	   pjax._handleResponse(responseText, request, href, options);
			}
		}
	});
}
var init1=false;
var navbtn=false;
*/
function scrollToElement(target, offset) {
  var scroll_offset = $(target).offset();
  $('body,html').animate({
    scrollTop: scroll_offset.top + (offset || 0),
    easing: 'swing',
  });
}

function scrollToBoard() {
  scrollToElement('#board', -$('#navbar').height());
}

// 防抖动函数
function debounce(func, wait, immediate) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    var later = function() {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}
$(document).ready(function () {
  // 顶部菜单的动效
  var navbar = $('#navbar');
  if (navbar.offset().top > 0) {
    navbar.addClass('navbar-custom');
    navbar.removeClass('navbar-dark');
  }
  $(window).scroll(function () {
    if (navbar.offset().top > 0) {
      navbar.addClass('navbar-custom');
      navbar.removeClass('navbar-dark');
    } else {
      navbar.addClass('navbar-dark');
    }
  });

  $('#navbar-toggler-btn').on('click', function () {
    $('.animated-icon').toggleClass('open');
    $('#navbar').toggleClass('navbar-col-show');
  });

  // 头图滚动动画
  $(window).scroll(function () {
    var oVal = $(window).scrollTop() / 3;
    $('#background[parallax="true"]').css({
      transform: 'translate3d(0,' + oVal + 'px,0)',
      '-webkit-transform': 'translate3d(0,' + oVal + 'px,0)',
      '-ms-transform': 'translate3d(0,' + oVal + 'px,0)',
      '-o-transform': 'translate3d(0,' + oVal + 'px,0)',
    });
  });

  // 向下滚动箭头的点击
  $('.scroll-down-bar').on('click', scrollToBoard);

  // 向顶部滚动箭头
  var topArrow = $('#scroll-top-button');
  var posDisplay = false;
  var scrollDisplay = false;
  // 位置
  var setTopArrowPos = function () {
    var boardRight = document.getElementById('board').getClientRects()[0].right;
    var bodyWidth = document.body.offsetWidth;
    var right = bodyWidth - boardRight;
    posDisplay = right >= 50;
    topArrow.css({
      'bottom': posDisplay && scrollDisplay ? '20px' : '-60px',
      'right': right - 64 + 'px',
    });
  };
  setTopArrowPos();
  $(window).resize(setTopArrowPos);
  // 显示
  var headerHeight = $('#board').offset().top;
  $(window).scroll(debounce(function () {
    var scrollHeight = document.body.scrollTop + document.documentElement.scrollTop;
    scrollDisplay = scrollHeight >= headerHeight;
    topArrow.css({
      'bottom': posDisplay && scrollDisplay ? '20px' : '-60px',
    });
  }, 20));
  // 点击
  topArrow.on('click', function () {
    $('body,html').animate({
      scrollTop: 0,
      easing: 'swing',
    });
  });
});
